<?php

class HUsers {
	function getIdByUsername($username) {
		$a = HSql::fetch2Array(HSql::doQuery("SELECT * FROM portal_users WHERE username = '$username'"));				
		return $a[0]['id'];
	}
	
	function getAllUsersExceptHost(){
		$a = HSql::fetch2Array(HSql::doQuery("SELECT * FROM portal_users WHERE role_id != '1'"));
		return $a;
	}
	
	function insert($username, $password, $email, $role_id = null){
		try {
			$sql = "INSERT INTO portal_users (username, password, email, role_id) 
					VALUES 				('".$username."', '".$password."', '".$email."','".$role_id."')";
			$result = HSql::doQuery($sql);	
		}catch (Exception $ex){
			throw new $ex->getMessage();
		}
		
		return  $result;
				
	}
	
	function getOneUserById($id){
		$sql = "SELECT * FROM portal_users WHERE id ='".$id."'";
		$a = HSql::fetch2Array(HSql::doQuery($sql));
		return $a;
	}
	
	function update($id, $email){
		try {
			$sql = "UPDATE portal_users SET email ='".$email."' WHERE id ='".$id."'";
			$result = HSql::doQuery($sql);
		}catch (Exception $ex){
			throw new $ex->getMessage();
		}
		return $result;
	}
	
	function delete($id){
		try {
			$sql = "DELETE FROM portal_users WHERE id = '".$id."'";
			$result = HSql::doQuery($sql);
		}catch (Exception $ex){
			throw new $ex->getMessage();
		}
		return $result;
	}
}

?>